clc;
clear;

% nolinear function
syms x;
eq1 = x^3 - 4*x^2 + 3*x + 11;
eq2 = -0.3*x^2 - log2(x) + 5;
eq3 = -exp(x^2-1) + sqrt(x^2 + 2);
eq4 = exp(x^2+7*x-30) - 10;
eq5 = sin(x)^2 - x^2 + 3;
% eq6 = exp(x)*cos(x) + log(x) - 2;
eq6 = sin(x)^2 - x^2 + 1;
eq7 = sin(x) + cos(2*x+1)^2 - 1;
eq8 = cos(x) + (1+exp(-2*x))^-1;
eq9 = x^3 - sin(x)^2 + 3*cos(x) + 5;
eq10 = x^7 - 2*x^5 + 3*x^4 - 7*x + 9;
eq = [eq1; eq2; eq3; eq4; eq5; eq6; eq7; eq8; eq9; eq10];

% solver's parameters
tolerance = 1e-6;
maxIteration = 500;
range = zeros(10,2);
range(1,:) = [-3 2];
range(2,:) = [0.01 5]; 
range(3,:) = [-1 3];
range(4,:) = [2 5];
range(5,:) = [0 5];
range(6,:) = [0 7];
range(7,:) = [-1 2];
range(8,:) = [-4 1];
range(9,:) = [-5 2];
range(10,:) = [-5 2];

% 错误代码结果：-1 超出迭代次数；0 找到解
% solve single proble --- determine the solution range
t = zeros(1,5);
[t(1,1),t(1,2),t(1,3),t(1,4),t(1,5)] = f_bisection_method(eq(10),[-5 2],tolerance,maxIteration);
t = real(t);

% solve all problems
n = 5*10;
r = zeros(n,4); % store the results
for i_eq = 6
    st = 5 * (i_eq-1);
    s1 = st + 1;
    [r(s1,1),r(s1,2),r(s1,3),r(s1,4),r(s1,5)] = f_bisection_method(eq(i_eq),range(i_eq,:),tolerance,maxIteration);
    s2 = st + 2;
    [r(s2,1),r(s2,2),r(s2,3),r(s2,4),r(s2,5)] = f_newton_method(eq(i_eq),range(i_eq,:),tolerance,maxIteration);
    s3 = st + 3;
    [r(s3,1),r(s3,2),r(s3,3),r(s3,4),r(s3,5)] = f_simpleNewton_method(eq(i_eq),range(i_eq,:),tolerance,maxIteration);
    s4 = st + 4;
    [r(s4,1),r(s4,2),r(s4,3),r(s4,4),r(s4,5)] = f_secant_method(eq(i_eq),range(i_eq,:),tolerance,maxIteration);
    s5 = st + 5;
    [r(s5,1),r(s5,2),r(s5,3),r(s5,4),r(s5,5)] = f_steffensen_method(eq(i_eq),range(i_eq,:),tolerance,1000);
end
r_r = real(r);
% [r(1,1),r(1,2),r(1,3),r(1,4)] = f_bisection_method(eq(1),range(1,:),tolerance,maxIteration);
% [r(2,1),r(2,2),r(2,3),r(2,4)] = f_newton_method(eq1,range(1,:),tolerance,maxIteration);
% [r(3,1),r(3,2),r(3,3),r(3,4)] = f_simpleNewton_method(eq1,range(1,:),tolerance,maxIteration);
% [r(4,1),r(4,2),r(4,3),r(4,4)] = f_secant_method(eq1,range(1,:),tolerance,maxIteration);
% [r(5,1),r(5,2),r(5,3),r(5,4)] = f_steffensen_method(eq1,range(1,:),tolerance,1000);
